﻿using AutoMapper;
using HomeWork911.Api.Write.Appliaction.Commond;
using HomeWork911.Api.Write.Dto;
using HomeWork911.Domain;
using HomeWork911.ErrorCode;
using HomeWork911.infrastrunceture;
using MediatR;

namespace HomeWork911.Api.Write.Appliaction.CommondHandler
{
    public class UpdatePermissionHandler:IRequestHandler<UpdatePermission,ApiResult<PermissionDto>>
    {
        private readonly IBaseIRepository<Permission> permission;
        private readonly IMapper mapper;

        public UpdatePermissionHandler(IBaseIRepository<Permission> permission, IMapper mapper)
        {
            this.permission = permission;
            this.mapper = mapper;
        }

        public async Task<ApiResult<PermissionDto>> Handle(UpdatePermission request, CancellationToken cancellationToken)
        {
            ApiResult<PermissionDto> result = new ApiResult<PermissionDto>();
            result.Code = ApiEnum.更改成功;
            result.Msg=ApiEnum.更改成功.ToString();

            Permission permissions=mapper.Map<Permission>(request);
            await permission.Update(permissions);

            return await Task.FromResult(result);
        }
    }
}
